package com.dgut.finaldemo.util;

import com.dgut.finaldemo.entity.Student;
import com.dgut.finaldemo.entity.Teacher;
import com.dgut.finaldemo.mapper.StudentMapper;
import com.dgut.finaldemo.mapper.TeacherMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Component
@Service
public class setClockScheduled {

    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private TeacherMapper teacherMapper;

    @Scheduled(cron = "0 0 0 * * ?")//每天凌晨更新clock为未打卡
    public void setNotClockSchduled(){
        System.out.println(new Date());
        List<Student> studentList = studentMapper.selectList(null);
        List<Teacher> teacherList = teacherMapper.selectList(null);
        for (Student student: studentList) {
            student.setClock("未打卡");
            studentMapper.updateById(student);
        }for (Teacher teacher: teacherList) {
            teacher.setClock("未打卡");
            teacherMapper.updateById(teacher);
        }
    }
}
